package com.chenyaowei.web.controller.product.spu;

import java.util.Arrays;
import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.chenyaowei.common.annotation.Log;
import com.chenyaowei.common.core.controller.BaseController;
import com.chenyaowei.common.core.domain.AjaxResult;
import com.chenyaowei.common.enums.BusinessType;
import com.chenyaowei.product.domain.CywProSpuImages;
import com.chenyaowei.product.service.ICywProSpuImagesService;
import com.chenyaowei.common.utils.poi.ExcelUtil;
import com.chenyaowei.common.core.page.TableDataInfo;

/**
 * spu图片集Controller
 *
 * @author 陈耀威
 * @date 2023-11-24
 */
@RestController
@RequestMapping("/product/spuImages")
public class CywProSpuImagesController extends BaseController
{
    @Autowired
    private ICywProSpuImagesService cywProSpuImagesService;

    @GetMapping("/list/{spuId}")
    public AjaxResult listBySpuId(@PathVariable("spuId") Long spuId)
    {
        List<CywProSpuImages> list = cywProSpuImagesService.selectListBySpuIds(Arrays.asList(spuId));
        return success(list);
    }

    /**
     * 查询spu图片集列表
     */
    @PreAuthorize("@ss.hasPermi('product:spuImages:list')")
    @GetMapping("/list")
    public TableDataInfo list(CywProSpuImages cywProSpuImages)
    {
        startPage();
        List<CywProSpuImages> list = cywProSpuImagesService.selectCywProSpuImagesList(cywProSpuImages);
        return getDataTable(list);
    }

    /**
     * 导出spu图片集列表
     */
    @PreAuthorize("@ss.hasPermi('product:spuImages:export')")
    @Log(title = "spu图片集", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CywProSpuImages cywProSpuImages)
    {
        List<CywProSpuImages> list = cywProSpuImagesService.selectCywProSpuImagesList(cywProSpuImages);
        ExcelUtil<CywProSpuImages> util = new ExcelUtil<CywProSpuImages>(CywProSpuImages.class);
        util.exportExcel(response, list, "spu图片集数据");
    }

    /**
     * 获取spu图片集详细信息
     */
    @PreAuthorize("@ss.hasPermi('product:spuImages:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(cywProSpuImagesService.selectCywProSpuImagesById(id));
    }

    /**
     * 新增spu图片集
     */
    @PreAuthorize("@ss.hasPermi('product:spuImages:add')")
    @Log(title = "spu图片集", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CywProSpuImages cywProSpuImages)
    {
        return toAjax(cywProSpuImagesService.insertCywProSpuImages(cywProSpuImages));
    }

    /**
     * 修改spu图片集
     */
    @PreAuthorize("@ss.hasPermi('product:spuImages:edit')")
    @Log(title = "spu图片集", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CywProSpuImages cywProSpuImages)
    {
        return toAjax(cywProSpuImagesService.updateCywProSpuImages(cywProSpuImages));
    }

    /**
     * 删除spu图片集
     */
    @PreAuthorize("@ss.hasPermi('product:spuImages:remove')")
    @Log(title = "spu图片集", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(cywProSpuImagesService.deleteCywProSpuImagesByIds(ids));
    }
}
